﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SksApp
{
    public partial class SettingsView : BaseView
    {
        DataTable dt = new DataTable();

        public SettingsView()
        {
            InitializeComponent();
            dataGridView1.EditingControlShowing += dataGridView1_EditingControlShowing;
            comboBox1.DropDownClosed += comboBox1_DropDownClosed;
        }

        void comboBox1_DropDownClosed(object sender, EventArgs e)
        {
            if (comboBox1.SelectedItem != null)
            {
                if (this.dataGridView1.CurrentCellAddress.X == 1)
                {
                    dataGridView1.CurrentCell.Value = comboBox1.SelectedItem.ToString();
                }
            }

        }
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Dispose();
            Event.Invoke(null, null);
        }

        private void btnKaydet_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                string prm = dt.Rows[i]["prm"].ToString();
                string val = dt.Rows[i]["val"].ToString();

                Information p = (Information)Enum.Parse(typeof(Information), prm);
                Settings.Instance.AddItems(p, val);
            }

            this.Dispose();
            Event.Invoke(null, null);
        }

        private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            comboBox1.Width = dataGridView1.Columns[1].Width;
            comboBox1.Height = dataGridView1.CurrentRow.Height;
            comboBox1.Visible = false;
            comboBox1.Items.Clear();

            bool gorun = false;
            if (dataGridView1.CurrentCell.Value != null && this.dataGridView1.CurrentCellAddress.X == 1)
                comboBox1.Text = dataGridView1.CurrentCell.Value.ToString();

            switch (dataGridView1.CurrentRow.Index)
            {
                case 7:
                case 8:
                case 9:
                    gorun = true;
                    foreach (string sPrinters in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
                    {
                        comboBox1.Items.Add(sPrinters);
                    }
                    break;
                case 10:
                    gorun = true;
                    comboBox1.Items.Add("YOK");
                    comboBox1.Items.Add("CAS");
                    comboBox1.Items.Add("TTB15");
                    comboBox1.Items.Add("Densi");
                    comboBox1.Items.Add("Terazi");
                    comboBox1.Items.Add("SnowRex");
                    comboBox1.Items.Add("CAS PD2");
                    break;
                case 13:
                    gorun = true;
                    comboBox1.Items.Add("YOK");
                    comboBox1.Items.Add("TKS-20-N");
                    comboBox1.Items.Add("Hugin_425TX");
                    comboBox1.Items.Add("Sharp");
                    comboBox1.Items.Add("İnter");
                    break;
            }

            if (gorun)
            {
                comboBox1.Visible = true;
                comboBox1.Location = new Point(dataGridView1.Columns[0].Width, dataGridView1.Location.Y + (dataGridView1.CurrentRow.Height * (dataGridView1.CurrentRow.Index + 1)));
            }

        }

        private void SettingsView_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("prm", typeof(string));
            dt.Columns.Add("disp", typeof(string));
            dt.Columns.Add("val", typeof(string));
            dt.Rows.Add("Sunucu", "Sunucu Adı", ".");
            dt.Rows.Add("Veritabani", "Veritabanı Adı", "MikroDB_V14_");
            dt.Rows.Add("VtKullaniciAdi", "Kullanıcı Adı", "sa");
            dt.Rows.Add("VtSifre", "Şifre", "");
            dt.Rows.Add("MagazaNo", "Mağaza No", "1");
            dt.Rows.Add("KasaNo", "Kasa No", "");
            dt.Rows.Add("SrmMerkezKodu", "Srm. Merkezi", "");
            dt.Rows.Add("FisYazicisi", "Fiş Yazıcı Adı", "");
            dt.Rows.Add("FaturaYazicisi", "Fatura Yazıcı Adı", "");
            dt.Rows.Add("EtiketYazicisi", "Etiket Yazıcı Adı", "");
            dt.Rows.Add("TeraziTipi", "Terazi Tipi", "");
            dt.Rows.Add("TeraziPortNo", "Terazi İletişim Portu", "");
            dt.Rows.Add("TeraziProgrami", "Terazi Yardımcı Programı", "");
            dt.Rows.Add("KasaTipi", "Yazarkasa Tipi", "");
            dt.Rows.Add("KasaPortNo", "Yazarkasa İletişim Portu", "");
            //dt.Rows.Add("DetayliSatisGonderilsin", "Yazarkasa Satış Gönderim Şekli", "");
            dt.Rows.Add("CekmeceProgrami", "Çekmece Programı", "");
            dt.Rows.Add("CekmeceAcilsin", "Evrak Bitişinde Çekmece Açılsın", "");
            dt.Rows.Add("YazdirmaModu", "Yazdırma Tipi", "");
            dt.Rows.Add("MusteriGostergePortu", "Müşteri Gösterge Portu", "");

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;
            dataGridView1.Columns[0].DataPropertyName = "disp";
            dataGridView1.Columns[1].DataPropertyName = "val";
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
